<?php

function get_admin_info($adminid) {
	global $DB;
	if (!$adminid) {
		return array();
	}
	$sql = "SELECT adminid, username, realname, e_name
			FROM admins
			WHERE adminid='$adminid'
			";
	return $DB->query_first($sql);
}

function get_admin_date($int_date, $p=1){ //$p
	$return_date = '-';
	if ($int_date == 943920000 || $int_date == 943891200 || $int_date == 0) { // 0000-00-00 00:00:00
		return $return_date;
	}
	$today_dateline = strtotime(date("Y-m-d"));
	$yesterday_dateline = (strtotime(date("Y-m-d")) - 3600 * 24);
	if ($int_date) {
		if (date("Y-m-d", $int_date) == date("Y-m-d")) {
			if($p)
                                $return_date = "今日 " . date("H:i", $int_date);
                        else
                                $return_date = "今日";
		} elseif (date("Y-m-d", $int_date) == date("Y-m-d", $yesterday_dateline)) {
                        if($p)
			        $return_date = "昨日 " . date("H:i", $int_date);
                        else
                                $return_date = "昨日";
		} else {
			if($p)
                                $return_date = date("y/m/d H:i", $int_date);
                        else
                                $return_date = date("y/m/d", $int_date);
		} 
	}
	return $return_date;
}

function format_pagelink($pagelink) {
	$pagelink = ereg_replace("pagenum=([0-9]*)(&)?", '', $pagelink);
	$pagelink = ereg_replace("perpage=([0-9]*)(&)?", '', $pagelink);
	$pagelink = ereg_replace("referer=([a-zA-z0-9]*)(&)?", '', $pagelink);
	$pagelink = ereg_replace("sort=([a-zA-z0-9]*)(&)?", '', $pagelink);
	$pagelink = ereg_replace("order=(asc|desc)(&)?", '', $pagelink);
	$pagelink = ereg_replace("submit=[^\&]*(&)?", '', $pagelink);
	$pagelink = ereg_replace("[a-z\_]+=\-2\&", '', $pagelink);
	$pagelink = ereg_replace("[a-z\_]+=\&", '', $pagelink);
	$pagelink = ereg_replace("(.*)\&$", '\1', $pagelink);
	return $pagelink;
}

function forbiden_filter($content, $to = '**'){
        
        static $file_array;
        static $count;
        
        if(!$file_array){
                $file = file_get_contents('/data/vhosts/xunlei.com/xiaozu/inc/config/forbiden_word_array.txt');        
                $file_array = unserialize($file);
        }

        $o_content = $content;
        //return $content;
        $len = mb_strlen($o_content, 'utf8');
        $replace_arr = array();
        $j = 0;
        for($i = 0; $i<$len-1; $i++){
                $single = mb_substr($o_content, $i, 1, 'utf8');
                if(isset($replace_arr[strtolower($single)]))continue;
                if($file_array[strtolower($single)]){
                        //$count += count($file_array[$single]);
                        
                        $single = strtolower($single);
                        if($to == 'red'){
                                $new = array();
                                foreach($file_array[$single] as $word){
                                        $new[] = '<font color=red>'.$word.'</font>';
                                }
                                
                                $content = str_ireplace($file_array[$single], $new, $content);
                        }else{
                                $content = str_ireplace($file_array[$single], $to, $content);        
                        }
                        
                        $j++;
                        
                        $replace_arr[$single] = 1;
                }else{
                        $replace_arr[strtolower($single)] = 0;
                }
        }
        //echo 'times: '.$j;
        //echo '<br />';
        //$count += $j;
        //return $content.'|'.$count;
        return $content;
}


function update_review($review_adminid = null, $table = null , $type = null, $org_display = null){  //table - thread、post    type 1:pass  2:unpass  3:del
        global $DB;

        if(!$review_adminid === null || $table === null || $type === null)return;
        
        if($type == 1){
                $kind = 'pass';
        }elseif($type == 2){
                $kind = 'unpass';
        }elseif($type == 3){
                $kind = 'delete';
        }
        
        $DB->query("use xiaozu_stat");
        
        $date = date('Y-m-d');
        $data = $DB->query_first("SELECT * FROM xiaozu_stat.review WHERE review_adminid = $review_adminid AND `date` = '$date'");
        
        if($type === $org_display)return false;
        
        if($data){
                if($org_display == 0){
                        $data = $DB->query("UPDATE xiaozu_stat.review SET {$table}_{$kind} = {$table}_{$kind}+1 WHERE review_adminid = $review_adminid AND `date` = '$date'");        
                }elseif($org_display == 1 && $type == 2){
                        $data = $DB->query("UPDATE xiaozu_stat.review SET {$table}_{$kind} = {$table}_{$kind}+1, {$table}_pass = {$table}_pass-1  WHERE review_adminid = $review_adminid AND `date` = '$date'");                                        
                }elseif($org_display == 2 && $type == 1){
                        $data = $DB->query("UPDATE xiaozu_stat.review SET {$table}_{$kind} = {$table}_{$kind}+1, {$table}_unpass = {$table}_unpass-1  WHERE review_adminid = $review_adminid AND `date` = '$date'");                                        
                }elseif($type == 3){
                        $data = $DB->query("UPDATE xiaozu_stat.review SET {$table}_{$kind} = {$table}_{$kind}+1 WHERE review_adminid = $review_adminid AND `date` = '$date'");                                        
                }
        }else{
                $data = $DB->query("INSERT INTO xiaozu_stat.review SET {$table}_{$kind} = 1, review_adminid = $review_adminid , `date` = '$date'");               
        }
        
        $DB->query("use xiaozu");
        
        return true;
}

?>